// Fill out your copyright notice in the Description page of Project Settings.

#include "Isalong2.h"
#include "WeaponHoldBase.h"




AWeaponHoldBase::AWeaponHoldBase()
{
	_attackOverlaper = CreateDefaultSubobject<UBoxComponent>(TEXT("OverplaAttacker"));
	_attackOverlaper->AttachTo(_skMesh);

	_attackOverlaper->OnComponentBeginOverlap.AddDynamic(this, &AWeaponHoldBase::OnAttackTargetBeginOverlap);
	_attackOverlaper->OnComponentEndOverlap.AddDynamic(this, &AWeaponHoldBase::OnAttackTargetEndOverlap);
}

void AWeaponHoldBase::SetUpData(FInteractData* data, int itemType)
{
	_dataPack = (FWeaponPack*)data;
	_itemType = itemType;
	SetBulletContains(_dataPack->_maxContains, false);
}

void AWeaponHoldBase::OnFireBegin()
{
	
}

void AWeaponHoldBase::OnFireEnd()
{
	
}

void AWeaponHoldBase::OnFireAnimationFired()
{
	
}

void AWeaponHoldBase::OnFireAnimationEnd()
{
	
}

int AWeaponHoldBase::GetAdditionValue()
{
	return GetBulletContains();
}

// maintain the pre attack list
void AWeaponHoldBase::OnAttackTargetBeginOverlap(AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
	for (int i=0;i<_preAttackActor.Num();i++)
	{
		if (_preAttackActor[i].GetActor()==OtherActor)
		{
			return;
		}
	}
	FHitResult hitRest = SweepResult; // do a copy
	_preAttackActor.Add(hitRest);
}

void AWeaponHoldBase::OnAttackTargetEndOverlap(AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
{
	for (int i=0;i<_preAttackActor.Num();i++)
	{
		if (_preAttackActor[i].GetActor()==OtherActor)
		{
			_preAttackActor.RemoveAt(i);
			return;
		}
	}
}
